<template>
  <el-dialog :visible.sync="visible" custom-class="group-dialog" :before-close="closeHandler">
    <div slot="title">
      <div class="dialog-title big_title">
        编辑分组
      </div>
    </div>
    <div>
      <el-input placeholder="请输入分组名称，最长64个字" class="font24 input_line" v-model="groups.name" maxlength="64"></el-input>
    </div>
   <div slot="footer">
     <el-button :loading="loading" type="primary" @click="saveGroup">保存</el-button>
   </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'GroupDialog',
  props: {
    group: {
      type: Object,
      required: true
    },
    value: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      groups: {},
      loading: false
    }
  },
  computed: {
    visible: {
      get () {
        return this.value
      },
      set (val) {
        this.$emit('input', val)
      }
    }
  },
  watch: {
    group (newVal, oldValue) {
      this.groups = newVal
    }
  },
  methods: {
    closeHandler (done) {
      done()
    },
    saveGroup () {
      this.loading = true
      this.visible = false
      // 0
      if (!this.groups.id) {
        this.groups.id = new Date().getTime()
      }
      this.$emit('editGroup', this.groups, this.groups.id)
      this.loading = false
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
